﻿using System;
using System.Data;
using System.Data.SqlServerCe;
using System.Collections.Generic;

using Common;
using Common.Entities;

namespace OrderSales.Model
{
    public class SelectGoodsModel
    {
        //private List<Good> allGoods;

        //public SelectGoodsModel ()
        //{
        //    allGoods = new List<Good>();
        //    LoadGoods();
        //}

        //private void LoadGoods ()
        //{
        //    try
        //    {
        //        using (SqlCeConnection connection = WorkDataBase.CreateConnection())
        //        {
        //            if (connection.State != ConnectionState.Open)
        //                connection.Open();
        //            string sqlQuery =
        //                "SELECT Goods.Name, Goods.Remaining, Goods.Price1, Goods.Price2, Goods.Price3, Goods.Price4, Goods.Article, Goods.Package, Trademarks.NameTrademark, Groups.NameGroup, Goods.IdGood " +
        //                "FROM Groups INNER JOIN Goods ON Groups.IdGroup = Goods.GroupId INNER JOIN Trademarks ON Goods.TrademarkId = Trademarks.IdTrademark ";
        //            if (!Settings.GetInstance().VisibleNullGoods)
        //                sqlQuery += " where Goods.Remaining > 0";
        //            using (SqlCeCommand command = new SqlCeCommand(sqlQuery, connection))
        //            {
        //                using (SqlCeDataReader dr = command.ExecuteReader())
        //                {
        //                    Good good;

        //                    int idGood = dr.GetOrdinal("IdGood");
        //                    int name = dr.GetOrdinal("Name");
        //                    int remaining = dr.GetOrdinal("Remaining");
        //                    int price1 = dr.GetOrdinal("Price1");
        //                    int price2 = dr.GetOrdinal("Price2");
        //                    int price3 = dr.GetOrdinal("Price3");
        //                    int price4 = dr.GetOrdinal("Price4");
        //                    int article = dr.GetOrdinal("Article");
        //                    int groupName = dr.GetOrdinal("NameGroup");
        //                    int tradeMarkName = dr.GetOrdinal("NameTrademark");
        //                    int package = dr.GetOrdinal("Package");

        //                    while (dr.Read())
        //                    {
        //                        good = new Good();
        //                        good.idGood = dr.GetInt32(idGood);
        //                        good.Name = dr.GetString(name);
        //                        good.Remaining = dr.IsDBNull(remaining) ? 0 : dr.GetDouble(remaining);
        //                        good.Price1 = dr.IsDBNull(price1) ? 0d : dr.GetDouble(price1);
        //                        good.Price2 = dr.IsDBNull(price2) ? 0d : dr.GetDouble(price2);
        //                        good.Price3 = dr.IsDBNull(price3) ? 0d : dr.GetDouble(price3);
        //                        good.Price4 = dr.IsDBNull(price4) ? 0d : dr.GetDouble(price4);
        //                        good.Article = dr.IsDBNull(article) ? "" : dr.GetString(article);
        //                        good.GroupName = dr.IsDBNull(groupName) ? "" : dr.GetString(groupName);
        //                        good.TradeMarkName = dr.IsDBNull(tradeMarkName) ? "" : dr.GetString(tradeMarkName);
        //                        good.Package = dr.IsDBNull(package) ? "" : dr.GetString(package);
        //                        allGoods.Add(good);
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    catch(Exception ex)
        //    {
        //        throw ex;
        //    }

        //}
        
        //public List<Good> AllGoods ()
        //{
        //    return allGoods;
        //}

    }
}
